package com.example.dou2204.tuijian;

import androidx.lifecycle.MutableLiveData;

import com.example.dou2204.baseMVVM.BaseViewModel;
import com.example.dou2204.entity.CommentEntity;
import com.example.dou2204.entity.ResultEntity;
import com.example.dou2204.entity.VideoEntity;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class TuijianViewModel extends BaseViewModel<TuijianRepo> {
    @Override
    protected TuijianRepo createRepo() {
        return new TuijianRepo();
    }

    public MutableLiveData<VideoEntity> success = new MutableLiveData<>();
    public MutableLiveData<String> fail = new MutableLiveData<>();
    public void video(int page,int size){
        repo.video(page,size,success,fail);
    }

    public MutableLiveData<ResultEntity> guanzhuSuccess = new MutableLiveData<>();
    public MutableLiveData<String> guanzhuFail = new MutableLiveData<>();
    public void guanzhu(String authname){
        Map<String,String> map = new HashMap<>();
        map.put("authname",authname);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;chatset=utf-8"), s);
        repo.guanzhu(body,guanzhuSuccess,guanzhuFail);
    }

    public MutableLiveData<ResultEntity> loveSuccess = new MutableLiveData<>();
    public MutableLiveData<String> loveFail = new MutableLiveData<>();
    public void love(int videoId){
        repo.love(videoId,loveSuccess,loveFail);
    }

    public MutableLiveData<ResultEntity> noloveSuccess = new MutableLiveData<>();
    public MutableLiveData<String> noloveFail = new MutableLiveData<>();
    public void nolove(int videoId){
        repo.nolove(videoId,noloveSuccess,noloveFail);
    }

    public MutableLiveData<CommentEntity> getcomSuccess = new MutableLiveData<>();
    public MutableLiveData<String> getcomFail = new MutableLiveData<>();
    public void getcomment(int id){
        repo.getcomment(id,getcomSuccess,getcomFail);
    }

    public MutableLiveData<CommentEntity> comSuccess = new MutableLiveData<>();
    public MutableLiveData<String> comFail = new MutableLiveData<>();
    public void comment(int videoId,String msg){
        Map<String,String> map = new HashMap<>();
        map.put("videoId",videoId+"");
        map.put("msg",msg);
        String s = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), s);
        repo.comment(body,comSuccess,comFail);
    }
}
